﻿/*
*VMukti -- An open source video conferencing platform.
*
* Copyright (C) 2007 - 2008, VMukti Solutions Pvt. Ltd.
*
* Hardik Sanghvi <hardik@vmukti.com>
*
* See http://www.vmukti.com for more information about
* the VMukti project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, forums and mailing lists
* for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace CRM.DataAccess
{
    public class ClsDynamicScriptDataService : ClsDataServiceBase
    {

        public ClsDynamicScriptDataService() : base() { }

        ////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///	Creates a new DataService and specifies a transaction with
        ///	which to operate
        /// </summary>
        ////////////////////////////////////////////////////////////////////////
        public ClsDynamicScriptDataService(IDbTransaction txn) : base(txn) { }


        public DataSet Options_GetAll(int QueID)
        {
            try
            {
                return ExecuteDataSet("Select ID,Options,ActionQueueID from QuestionOptions where QuestionID=" + QueID + ";", CommandType.Text, null);
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "Options_GetAll()--:--ClsDynamicScriptDataService.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
                return null;
            }

        }

        public DataSet Answer_GetAll()
        {
            try
            {
                return null;
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "Options_GetAll()--:--ClsDynamicScriptDataService.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
                return null;
            }
            //return ExecuteDataSet("Select ID,Options,ActionQueueID from QuestionOptions where QuestionID=" + QueID + ";", CommandType.Text, null);
        }

        public DataSet Questions_GetAll(int ScriptID)
        {
            try
            {
                return ExecuteDataSet("Select ID,QuestionName,QuestionText,Category from Question where ScriptID=" + ScriptID + ";", CommandType.Text, null);
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "Options_GetAll()--:--ClsDynamicScriptDataService.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
                return null;
            }
        }

        public DataSet Lead_GetAll(int LeadID, int LeadFieldID)
        {
            try
            {
                if (LeadFieldID == 2)
                {
                    return ExecuteDataSet("Select Leads.ID,StateName as PropertyValue from Leads,Location,State where Leads.LocationID = Location.ID and Location.StateID = State.ID and Leads.ID =" + LeadID + ";", CommandType.Text, null);

                }
                else if (LeadFieldID == 3)
                {
                    return ExecuteDataSet("Select Leads.ID,ZipCode as PropertyValue from Leads,Location,Zipcode where Leads.LocationID = Location.ID and Location.ZipCodeID = Zipcode.ID and Leads.ID =" + LeadID + ";", CommandType.Text, null);

                }
                else
                {
                    return ExecuteDataSet("Select ID,PropertyValue from LeadDetail where LeadID=" + LeadID + " and LeadFieldID=" + LeadFieldID + ";", CommandType.Text, null);

                }
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "Lead_GetAll()--:--ClsDynamicScriptDataService.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
                return null;
            }
        }


        public void Answer_Save(int CallID, int QusOptionID)
        {
            try
            {
                SqlCommand cmd;
                ExecuteNonQuery(out cmd, "spAAnswer",
                    CreateParameter("@pCallId", SqlDbType.BigInt, CallID),
                    CreateParameter("@pQusOptionId", SqlDbType.BigInt, QusOptionID));
                cmd.Dispose();
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "Answer_Save()--:--ClsDynamicScriptDataService.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);

            }
        }

        //public DataSet User_GetByID(int ID)
        //{
        //    return ExecuteDataSet("spGUserInfoPayroll", CommandType.StoredProcedure, CreateParameter("@pID", SqlDbType.Int, ID));
        //}

        //public void User_Save(ref int ID, string displayame,int roleID,string firstName,string lastName,string eMail,string password,bool isActive,int byUserId,float ratePerHour,float overTimeRate,float doubleRatePerHour,float doubleOverTimeRate )
        //{
        //    SqlCommand cmd;
        //    ExecuteNonQuery(out cmd, "spAEUserInfoPayroll",
        //        CreateParameter("@pID", SqlDbType.Int, ID),
        //        CreateParameter("@pDisplayName", SqlDbType.NVarChar, displayame, 100),
        //        CreateParameter("@pRoleID", SqlDbType.BigInt, roleID),
        //        CreateParameter("@pFirstName", SqlDbType.NVarChar, firstName, 50),
        //        CreateParameter("@pLastName", SqlDbType.NVarChar, lastName, 50),
        //        CreateParameter("@pEMail", SqlDbType.NVarChar, eMail, 256),
        //        CreateParameter("@pPassword", SqlDbType.NVarChar, password, 50),
        //        CreateParameter("@pIsActive", SqlDbType.Bit, isActive),
        //        CreateParameter("@pByUserID", SqlDbType.BigInt, byUserId),
        //        CreateParameter("@pRatePerHour", SqlDbType.Float, ratePerHour),
        //        CreateParameter("@pOverTimeRate", SqlDbType.Float, overTimeRate),
        //        CreateParameter("@pDoubleRatePerHour", SqlDbType.Float, doubleRatePerHour),
        //        CreateParameter("@pDoubleOverTimeRate", SqlDbType.Float, doubleOverTimeRate));

        //    cmd.Dispose();
        //}

        //public void User_Delete(int ID)
        //{
        //    ExecuteNonQuery("spDUserInfoPayroll", CreateParameter("@pID", SqlDbType.Int, ID));
        //}

    }
}
